package com.dsteiner.xelavos.client;



import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.RoundBorder;
import com.dsteiner.widgets.client.RoundBorder.RoundBorderModel;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.IWidget;
import com.dsteiner.widgets.client.Widgets.IWidgetBuilder;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.Widgets.ScrollPanelExt;
import com.dsteiner.widgets.client.resources.RoundBorderCssResource;
import com.dsteiner.widgets.client.resources.RoundBorderResources;
import com.dsteiner.xelavos.client.controller.TopNewController;
import com.dsteiner.xelavos.client.model.AuthenticationModel;
import com.dsteiner.xelavos.client.model.DisplayModel;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.dsteiner.xelavos.client.model.TopNewModel;
import com.dsteiner.xelavos.client.resources.XelavosImageBundle;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class TopNewWidget extends LazyWidget implements IWidgetBuilder{
	
	private TopNewController topNewController = new TopNewController();
	private final TopNewModel topNewModel;
	private final MainTabModel mainTabModel;
	private final AuthenticationModel authenticationModel;
	
	public TopNewWidget(TopNewModel usersModel, MainTabModel mainTabModel, 
			AuthenticationModel authenticationModel) {
		this.topNewModel = usersModel;
		this.mainTabModel = mainTabModel;
		this.authenticationModel = authenticationModel;
	}

	@Override
	public Widget createContentWidget() {
		FlowPanelExt mainPanel = new FlowPanelExt();
		ScrollPanelExt recentScrollPanel = new ScrollPanelExt();
		ScrollPanelExt activeScrollPanel = new ScrollPanelExt();
		FlowPanelExt recentContentPanel = new FlowPanelExt();
		FlowPanelExt activeContentPanel = new FlowPanelExt();
		RoundBorderCssResource css = RoundBorderResources.Util.INSTANCE.css();
		RoundBorderModel roundBorderModel = new RoundBorderModel();
		roundBorderModel.setContentWidget(mainPanel);
		roundBorderModel.setCssResource(css);
		RoundBorder decoratorPanel = new RoundBorder(roundBorderModel);
		
		recentScrollPanel.setWidget((Widget)recentContentPanel);
		activeScrollPanel.setWidget((Widget)activeContentPanel);
		
		Image newImage = XelavosImageBundle.Util.getInstance().newIcon().createImage();
		Image topImage = XelavosImageBundle.Util.getInstance().topIcon().createImage();
		mainPanel.add(newImage);
		mainPanel.add((Widget)recentScrollPanel);
		mainPanel.add(topImage);
		mainPanel.add((Widget)activeScrollPanel);
		
		topImage.addStyleName(XelavosResources.INSTANCE.css().header());
		newImage.addStyleName(XelavosResources.INSTANCE.css().header());
		setStyleName(XelavosResources.INSTANCE.css().topNewWidget());
		recentScrollPanel.addStyleName(XelavosResources.INSTANCE.css().scrollPanel());
		activeScrollPanel.addStyleName(XelavosResources.INSTANCE.css().scrollPanel());
		recentScrollPanel.getElement().getStyle().setProperty("overflowX", "hidden");
		activeScrollPanel.getElement().getStyle().setProperty("overflowX", "hidden");
		
		topNewController.registerUsersWidget(this);
		topNewController.registerAuthenticationModel(authenticationModel);
		topNewController.registerRecentContentPanel(recentContentPanel);
		topNewController.registerRecentScrollPanel(recentScrollPanel);
		topNewController.registerActiveScrollPanel(activeScrollPanel);
		topNewController.registerActiveContentPanel(activeContentPanel);
		topNewController.registerTopNewModel(topNewModel);
		topNewController.registerWidgetBuilder(this);
		topNewController.registerJsUtil(JsUtil.getInstance());
		topNewController.registerMainTabModel(mainTabModel);
		return decoratorPanel;
	}

	public IWidget createWidget(Object model) {
		DisplayModel displayModel = (DisplayModel) model;
		DisplayWidget displayWidget = new DisplayWidget(displayModel, authenticationModel);
		return displayWidget;
	}

}
